package com.xyc.petmallsystem.repository;

import com.xyc.petmallsystem.pojo.Cat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Joel
 * @date 2021/11/28
 */
public interface CatRepository extends JpaRepository<Cat, Integer> {

    /*
    根据类别查找
     */
    @Query(value = "select * from cat where cat_sort = :cat_sort", nativeQuery = true)
    List<Cat> findCat(String cat_sort);

    /*
    查询数量
     */
    @Query(value = "select count(*) from cat ", nativeQuery = true)
    Integer getCatCount();

    /*
    模糊搜索  _猫_   %猫%
     */
    @Query(value = "select * from cat where cat_sort like :content " +
            "or details like :content " +
            "or memo like :content " +
            "or sex = :content", nativeQuery = true)
    List<Cat> search(String content);
}
